package org.alanlau.instance;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 测试类
 *
 * @author alan
 * @version 1.0
 * @date 2020/1/12 9:02
 */
public class TestInstance {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        // 构造方法实例化
        BeanClass b1 = (BeanClass) context.getBean("constructorInstance");
        BeanClass b2 = (BeanClass) context.getBean("constructorInstance2");
        System.out.println(b1 + b1.message);
        System.out.println(b2 + b2.message);

        // 静态工厂实例化
        BeanClass b3 = (BeanClass) context.getBean("staticFactoryInstance");
        System.out.println(b3 + b3.message);

        // 实例工厂实例化
        BeanClass b4 = (BeanClass) context.getBean("instanceFactoryInstance");
        System.out.println(b4 + b4.message);
    }
}
